package edu.zut.bailan.timecard.web.spring.controller;

import java.awt.print.Pageable;
import java.util.HashMap;
import java.util.Map;


import edu.zut.bailan.base.web.spring.controller.GenericController;
import edu.zut.bailan.timecard.domain.TimeCard;
import edu.zut.bailan.timecard.service.TimeCardManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

@Controller
@RequestMapping(value = "/Overdue", produces = { MediaType.APPLICATION_JSON_VALUE })
public class TimeCardController extends GenericController<TimeCard, Long, TimeCardManager> {

        public static final Logger logger = LogManager.getLogger(TimeCardController.class.getName());

    TimeCardManager timeCardManager;



    @Resource
        public void setOverdueManager(TimeCardManager timeCardManager) {
            this.timeCardManager = timeCardManager;
            this.manager = this.timeCardManager;
        }



        @RequestMapping(value="/findAll/{page}/{pageSize}",method = {RequestMethod.GET, RequestMethod.POST})
        public Map<String,Object> findAllUser(@PathVariable("page") int page, @PathVariable("pageSize") int pageSize){
            Sort sort = Sort.by(Sort.Direction.DESC,"id");
            Pageable pageable = (Pageable) PageRequest.of(page,pageSize, sort);
            Page<TimeCard> list = timeCardManager.findAll((org.springframework.data.domain.Pageable) pageable);
            HashMap<String,Object> map = new HashMap<>();
            map.put("number",list.getTotalElements());
            map.put("userList",list.getContent());
            logger.info("----------->"+list.getContent());
            //map集合转化为JSON字符串进行数据传输
            return map;
        }

        public int deleteUser(long id){
            return 0;
        }
}
